//
//  Oos4ios.m
//  Oos4ios
//
//  Created by Pablo Gonzalez on 2/21/11.
//  Copyright 2011 11870.com. All rights reserved.
//

#import <oos4ios/Oos4ios.h>
#import <oos4ios/Auth/AnonimousAuthenticationHandler.h>
#import "../Persistence/OosManagedContext.h"
#import "OosMeLoader.h"


@implementation Oos4ios

+ (OosServiceDao *) getServiceDao
{
	// TODO
	return nil;
}

static Oos4ios *instance;

+ (Oos4ios *) instance
{
	if (!instance) {
		instance = [[Oos4ios alloc] init];
		instance.authenticationHandler = [AnonimousAuthenticationHandler handler];
	}
	return instance;
}

- (OosServiceDao *) serviceDao
{
	return [OosServiceDao dao];
}

- (OosReviewDao *) reviewDao: (OosService *) service
{
	return [OosReviewDao daoFromService:service];
}

- (OosMultimediaDao *) multimediaDaoFromService:(OosService *)service
{
	return [OosMultimediaDao daoFromService: service];
}

- (OosContactDao *) contactDaoFromUser: (OosUser *) user
{
	return [OosContactDao daoFromUser: user];
}

- (OosCheckinDao *) checkinDaoFromUser: (OosUser *) user
{
	return [OosCheckinDao daoFromUser: user];
}

- (OosCheckinDao *) checkinDaoFromService: (OosService *) service
{
	return [OosCheckinDao daoFromService:service];
}

- (OosActivityDao *) activityDaoFromUser: (OosUser *) user
{
	return [OosActivityDao daoFromUser:user];
}

- (OosServiceDao *) serviceDaoFromUser: (OosUser *) user
{
	return [OosServiceDao daoFromUser: user];
}

- (OosListDao *) listDaoFromUser: (OosUser *) user
{
	return [OosListDao daoFromUser:user];
}

- (OosTagDao *) tagDaoFromUser: (OosUser *) user
{
	return [OosTagDao daoFromUser: user];
}

- (OosMe *) me
{
    return [OosMe me];
}

- (void) loadMe: (id<LoadMeCallback>) callback
{
    [OosMeLoader startLoadingMe: callback];
}

@synthesize authenticationHandler = mAuthenticationHandler;

- (NSManagedObjectContext *) managedContext
{
	return [OosManagedContext context];
}

- (BOOL) clearContext 
{
    return [OosManagedContext clearContext];
}

- (BOOL) authenticated
{
	return mAuthenticationHandler && ![mAuthenticationHandler isAnonymous];
}

- (void)dealloc
{
    [mAuthenticationHandler release];
    [mMe release];
    [mStoreCoordinator release];
    [super dealloc];
}

@end
